import React from "react";
import PubSub from "pubsub-js";

export default function Item({ todo }) {
  const deleteItem = (id) => {
    PubSub.publish("deleteItem", id);
  };

  const chooseItem = (id) => {
    PubSub.publish("chooseItem", id);
  };
  return (
    <li>
      <label>
        <input
          type="checkbox"
          checked={todo.done}
          onChange={() => chooseItem(todo.id)}
        />
        <span>{todo.title}</span>
      </label>
      <button className="btn btn-danger" onClick={() => deleteItem(todo.id)}>
        删除
      </button>
    </li>
  );
}
